package com.prs.crm.action.assets;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.action.warning.AutoCodeAction;
import com.prs.crm.annotation.Clew;
import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.assets.AssetsLingYong;
import com.prs.crm.domain.assets.AssetsRegister;
import com.prs.crm.domain.assets.AssetsRevert;
import com.prs.crm.domain.flow.FlowNodePerson;
import com.prs.crm.domain.flow.FlowVerifyDetail;
import com.prs.crm.domain.flow.WorkFlow;
import com.prs.crm.domain.flow.WorkFlowAndPerson;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.warning.AutoCode;
import com.prs.crm.service.assets.AssetsRegisterService;
import com.prs.crm.service.assets.AssetsRevertService;
import com.prs.crm.service.flow.FlowNodePersonService;
import com.prs.crm.service.flow.FlowVerifyDetailService;
import com.prs.crm.service.flow.WorkFlowAndPersonService;
import com.prs.crm.service.flow.WorkFlowNodeService;
import com.prs.crm.service.flow.WorkFlowService;
import com.prs.crm.service.warning.AutoCodeService;

public class AssetsRevertAction extends BaseAction{
	private PaginationSupport pagination;
	private Integer[] ids;
	private AssetsRevertService assetsRevertService;
	private AssetsRevert assetsRevert;
	private String rec;
	private AssetsRegisterService assetsRegisterService;
	private File upload;
	private String uploadFileName;
	private FlowVerifyDetail detail;
	private List<WorkFlow> workFlow;
	private WorkFlow workFlows;
	private WorkFlowService workflowService;
	private List<FlowNodePerson> nodePerson;
	private FlowNodePersonService flowNodePersonService;
	private WorkFlowNodeService workFlowNodeService;
	private FlowVerifyDetailService flowVerifyDetailService;
	private FlowVerifyDetail flowVerifyDetail;
	private WorkFlowAndPerson workFlowAndPerson;
	private WorkFlowAndPersonService workFlowAndPersonService;
	private AutoCodeService autoCodeService;
	private String codeNum;
	private List<WorkFlowAndPerson> workFlowAndPersons;
	private List<FlowVerifyDetail> flowVerifyDetails;
	public List<WorkFlowAndPerson> getWorkFlowAndPersons() {
		return workFlowAndPersons;
	}
	public void setWorkFlowAndPersons(List<WorkFlowAndPerson> workFlowAndPersons) {
		this.workFlowAndPersons = workFlowAndPersons;
	}
	public List<FlowVerifyDetail> getFlowVerifyDetails() {
		return flowVerifyDetails;
	}
	public void setFlowVerifyDetails(List<FlowVerifyDetail> flowVerifyDetails) {
		this.flowVerifyDetails = flowVerifyDetails;
	}
	public FlowVerifyDetail getDetail() {
		return detail;
	}
	public void setDetail(FlowVerifyDetail detail) {
		this.detail = detail;
	}
	public List<WorkFlow> getWorkFlow() {
		return workFlow;
	}
	public void setWorkFlow(List<WorkFlow> workFlow) {
		this.workFlow = workFlow;
	}
	public WorkFlow getWorkFlows() {
		return workFlows;
	}
	public void setWorkFlows(WorkFlow workFlows) {
		this.workFlows = workFlows;
	}
	public WorkFlowService getWorkflowService() {
		return workflowService;
	}
	public void setWorkflowService(WorkFlowService workflowService) {
		this.workflowService = workflowService;
	}
	public List<FlowNodePerson> getNodePerson() {
		return nodePerson;
	}
	public void setNodePerson(List<FlowNodePerson> nodePerson) {
		this.nodePerson = nodePerson;
	}
	public FlowNodePersonService getFlowNodePersonService() {
		return flowNodePersonService;
	}
	public void setFlowNodePersonService(FlowNodePersonService flowNodePersonService) {
		this.flowNodePersonService = flowNodePersonService;
	}
	public WorkFlowNodeService getWorkFlowNodeService() {
		return workFlowNodeService;
	}
	public void setWorkFlowNodeService(WorkFlowNodeService workFlowNodeService) {
		this.workFlowNodeService = workFlowNodeService;
	}
	public FlowVerifyDetailService getFlowVerifyDetailService() {
		return flowVerifyDetailService;
	}
	public void setFlowVerifyDetailService(
			FlowVerifyDetailService flowVerifyDetailService) {
		this.flowVerifyDetailService = flowVerifyDetailService;
	}
	public FlowVerifyDetail getFlowVerifyDetail() {
		return flowVerifyDetail;
	}
	public void setFlowVerifyDetail(FlowVerifyDetail flowVerifyDetail) {
		this.flowVerifyDetail = flowVerifyDetail;
	}
	public WorkFlowAndPerson getWorkFlowAndPerson() {
		return workFlowAndPerson;
	}
	public void setWorkFlowAndPerson(WorkFlowAndPerson workFlowAndPerson) {
		this.workFlowAndPerson = workFlowAndPerson;
	}
	public WorkFlowAndPersonService getWorkFlowAndPersonService() {
		return workFlowAndPersonService;
	}
	public void setWorkFlowAndPersonService(
			WorkFlowAndPersonService workFlowAndPersonService) {
		this.workFlowAndPersonService = workFlowAndPersonService;
	}
	public AutoCodeService getAutoCodeService() {
		return autoCodeService;
	}
	public void setAutoCodeService(AutoCodeService autoCodeService) {
		this.autoCodeService = autoCodeService;
	}
	public String getCodeNum() {
		return codeNum;
	}
	public void setCodeNum(String codeNum) {
		this.codeNum = codeNum;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public AssetsRevertService getAssetsRevertService() {
		return assetsRevertService;
	}
	public void setAssetsRevertService(AssetsRevertService assetsRevertService) {
		this.assetsRevertService = assetsRevertService;
	}
	public AssetsRevert getAssetsRevert() {
		return assetsRevert;
	}
	public void setAssetsRevert(AssetsRevert assetsRevert) {
		this.assetsRevert = assetsRevert;
	}
	public String getRec() {
		return rec;
	}
	public void setRec(String rec) {
		this.rec = rec;
	}
	public AssetsRegisterService getAssetsRegisterService() {
		return assetsRegisterService;
	}
	public void setAssetsRegisterService(AssetsRegisterService assetsRegisterService) {
		this.assetsRegisterService = assetsRegisterService;
	}
	///////////////////////////////////////////////////////////////////////////////
	@Action("listAssetsRevert")
	public String listAssetsRevert(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRevert.class);
		this.setPagination(this.assetsRevertService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("editAssetsRevert")
	public String editAssetsRevert(){
		if(assetsRevert == null){
			rec = "";
		}else{
			rec="7";
		}
		this.workFlow=this.getWorkflowService().getWorkFlow("固定资产归还流程");
		codeNum=getCode("ZCGH");
		return SUCCESS;
	}
	//暂存
	@Action(value="saveAssetsRevert",results={
			@Result(name="success",type="redirect",location="listAssetsRevert"),
			@Result(name="error",type="chain",location="editAssetsRevert")})
	public String saveAssetsRevert(){
		if (upload!=null) {
			this.assetsRevert.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		if (assetsRevert.getNumber()==null || "".equals(assetsRevert.getNumber().trim())) {
			this.addActionError("编号不能为空！");
			return ERROR;
		}
		if (assetsRevert.getUser()==null || "".equals(assetsRevert.getUser().trim())) {
			this.addActionError("申请人不能为空！");
			return ERROR;
		}
		if (assetsRevert.getDate()==null || "".equals(assetsRevert.getDate())) {
			this.addActionError("日期不能为空！");
			return ERROR;
		}
		if(ids != null){
			List<AssetsRegister> regs = this.assetsRegisterService.getAllByids(ids);
			for(int i=0;i<regs.size();i++){
				regs.get(i).setAsssteRevert(assetsRevert);
			}
			assetsRevert.setAssetsRegisters(new HashSet<AssetsRegister>(regs));
		}
		assetsRevert.setType(0);
		this.assetsRevertService.saveRevertAndHistory(assetsRevert);
		return SUCCESS;
	}
	//提交
	@Action(value="sendAssetsRevert",results={
			@Result(name="success",type="redirect",location="listAssetsRevert"),
			@Result(name="error",type="chain",location="editAssetsRevert")})
	public String sendAssetsRevert(){
		if (upload!=null) {
			this.assetsRevert.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		if (assetsRevert.getNumber()==null || "".equals(assetsRevert.getNumber().trim())) {
			this.addActionError("编号不能为空！");
			return ERROR;
		}
		if (assetsRevert.getUser()==null || "".equals(assetsRevert.getUser().trim())) {
			this.addActionError("申请人不能为空！");
			return ERROR;
		}
		if (assetsRevert.getDate()==null || "".equals(assetsRevert.getDate())) {
			this.addActionError("日期不能为空！");
			return ERROR;
		}
		if(ids != null){
			List<AssetsRegister> regs = this.assetsRegisterService.getAllByids(ids);
			for(int i=0;i<regs.size();i++){
				regs.get(i).setAsssteRevert(assetsRevert);
			}
			assetsRevert.setAssetsRegisters(new HashSet<AssetsRegister>(regs));
		}
		assetsRevert.setType(1);
		this.assetsRevertService.saveRevertAndHistory(assetsRevert);
		
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
		.getFlowNodePerson(assetsRevert.getWorkFlow());
		for (FlowNodePerson ob : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(ob.getWorkFlow());
			workFlowAndPerson.setNodePersonId(ob.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(ob.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(ob.getWorkFlowNode().getType()+"");
			String[] persons=ob.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setAssetsRevert(assetsRevert);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);

		}
		return SUCCESS;
	}
	@Action("viewAssetsRevert")
	public String viewAssetsRevert(){
		if(assetsRevert == null){
			rec = "";
		}else{
			rec="1";
		}
		return SUCCESS;
	}
	@Action("viewMyAppAssetsRevert")
	public String viewMyAppAssetsRevert(){
		return SUCCESS;
	}
	/*******************************我的归还**************************************/
	@Action("listMyAssetsRevert")
	public String listMyAssetsRevert(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRevert.class)
		.add(Restrictions.eq("person.id", AppContext.getAccountContext().getUser().getId()));
		this.setPagination(this.assetsRevertService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("listMyAppAssetsRevert")
	public String listMyAppAssetsRevert(){
		Person currentperson = AppContext.getAccountContext().currentUser();
		List<AssetsRevert> ar=this.getAssetsRevertService().getAllAssetsRevert();
		 for (AssetsRevert ob : ar) {
			 List<WorkFlowAndPerson> wf = this.getWorkFlowAndPersonService().getWorkFlowAndPersonByAssetsRevert(ob.getWorkFlow(),ob);
				//顺序调整
			 List<WorkFlowAndPerson> wff=  sequens(wf);
			 for(WorkFlowAndPerson obb:wff){
				 if("1".equals(obb.getFlowstate())) {
					 if ("1".equals(obb.getType())) {
						 String[] personss=obb.getNodePersonId().split(",");
						 for(String persons:personss){
							 if((currentperson.getId()+"").equals(persons)){
								 if (ob.getPersonAppProcess()!=null) {
									 String[] personapp=ob.getPersonAppProcess().split(",");
									 for (String pers : personapp) {
										 if (currentperson.getResume().getName().equals(pers)) {
											ob.setPersonAppState(2);
											this.getAssetsRevertService().submit(ob);
											break;
										}else{
											ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
										    ob.setType(1);
										    ob.setPersonAppState(1);
										    this.getAssetsRevertService().submit(ob);  
										}
									 }
								 }else{
									ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
								    ob.setType(1);
								    ob.setPersonAppState(1);
								    this.getAssetsRevertService().submit(ob); 
								 }
							 }else{
								 
							 }
						 }
						 break;
					 }
					 if ("2".equals(obb.getType())) {
							String[] personss=obb.getNodePersonId().split(",");
							for(String persons:personss){
								System.out.println(persons);
								if((currentperson.getId()+"").equals(persons)){
									 if (ob.getPersonAppProcess()!=null) {
											String[] personapp=ob.getPersonAppProcess().split(",");
											 for (String pers : personapp) {
												if (currentperson.getResume().getName().equals(pers)) {
													ob.setPersonAppState(2);
													 this.getAssetsRevertService().submit(ob);
													break;
												}else{
													 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
													    ob.setType(1);
													    ob.setPersonAppState(1);
													    this.getAssetsRevertService().submit(ob);  
												}
											}
										}else{
											 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
											    ob.setType(1);
											    ob.setPersonAppState(1);
											    this.getAssetsRevertService().submit(ob);
										}
								}else{
									
								}
							}
							break;
						 }
					 if ("3".equals(obb.getType())) {
							String[] personss=obb.getNodePersonId().split(",");
							for(String persons:personss){
							System.out.println(persons);
								if((currentperson.getId()+"").equals(persons)){
									 if (ob.getPersonAppProcess()!=null) {
											String[] personapp=ob.getPersonAppProcess().split(",");
											 for (String pers : personapp) {
												if (currentperson.getResume().getName().equals(pers)) {
													ob.setPersonAppState(2);
													 this.getAssetsRevertService().submit(ob);
													break;
												}else{
													 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
													    ob.setType(1);
													    ob.setPersonAppState(1);
													    this.getAssetsRevertService().submit(ob);  
												}
											}
										}else{
											 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
											    ob.setType(1);
											    ob.setPersonAppState(1);
											    this.getAssetsRevertService().submit(ob);
										}
								}else{
									
								}
							}
							break;
						 }
					 if ("5".equals(obb.getType())) {
							String[] personss=obb.getNodePersonId().split(",");
							for(String persons:personss){
							System.out.println(persons);
								if((currentperson.getId()+"").equals(persons)){
									 if (ob.getPersonAppProcess()!=null) {
											String[] personapp=ob.getPersonAppProcess().split(",");
											 for (String pers : personapp) {
												if (currentperson.getResume().getName().equals(pers)) {
													ob.setPersonAppState(2);
													 this.getAssetsRevertService().submit(ob);
													break;
												}else{
													 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
													    ob.setPersonAppState(1);
													    this.getAssetsRevertService().submit(ob);  
												}
											}
										}else{
											 ob.setShowstate(AppContext.getAccountContext().currentUser().getId()+"：1"); 
											    ob.setPersonAppState(1);
											    this.getAssetsRevertService().submit(ob);
										}
								}else{
									
								}
							}
							break;
						 }
				 	}
			 	}
		 	}
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRevert.class);
		criteria.add(Restrictions.eq("showstate",AppContext.getAccountContext().currentUser().getId()+"：1"));//1：显示
		criteria.add(Restrictions.isNotNull("workFlow"));//审签流程不为空值	
		criteria.add(Restrictions.eq("personAppState", 1));
		criteria.add(Restrictions.eq("type", 1));// 1：未审核
		this.setPagination(this.assetsRevertService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Clew(results = { "success" })
	@Action(value = "saveApplAssetsRevert", results = { @Result(name = "success", type = "redirect", location = "listMyAppAssetsRevert") })
	public String saveApplAssetsLingYong() {
		List<WorkFlowAndPerson> wf=this.getWorkFlowAndPersonService().getWorkFlowAndPersonByAssetsRevert(assetsRevert.getWorkFlow(), assetsRevert);
		List<WorkFlowAndPerson> wfp=sequens(wf);
		for (WorkFlowAndPerson wff : wfp) {
			if("1".equals(wff.getFlowstate())){
				String[] personss=wff.getNodePersonId().split(",");
				for (String persons : personss) {
					System.out.println(persons);
					if((AppContext.getAccountContext().currentUser().getId()+"").equals(persons)){
						FlowVerifyDetail detail=new FlowVerifyDetail();
						if (upload!=null) {
							this.flowVerifyDetail.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
							detail.setAttach(flowVerifyDetail.getAttach());
						}
						detail.setWorkFlowAndPerson(wff);
						detail.setExecutor(AppContext.getAccountContext().currentUser());
						detail.setResult(flowVerifyDetail.getResult());
						detail.setOpinion(flowVerifyDetail.getOpinion());
						this.getFlowVerifyDetailService().save(detail);
						if("5".equals(wff.getType())){
							if (wff.getPersonNum()==1) {
								if (flowVerifyDetail.getResult()==4) {
									wff.setFlowstate("2");
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(4);
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSplc("审核完成");
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}else if(flowVerifyDetail.getResult()==1) {
									wff.setFlowstate("2");
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(2);
									assetsRevert.setShowstate("2");
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc("审核完成");
									this.getAssetsRevertService().submit(assetsRevert);
									List<AssetsRegister> ar=this.getAssetsRegisterService().getAssetsRegistersByRevert(assetsRevert);
									for (AssetsRegister ars : ar) {
										ars.setState("已归还");
										this.getAssetsRegisterService().submit(ars);
									}
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}else{
								if (flowVerifyDetail.getResult()==4) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum()-1);
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(4);
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc("审核完成");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}else if(flowVerifyDetail.getResult()==1) {
									wff.setPersonNum(wff.getPersonNum()-1);
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(1);
									assetsRevert.setShowstate("2");
									if (assetsRevert.getPersonAppProcess()==null || "".equals(assetsRevert.getPersonAppProcess().trim())) {
										assetsRevert.setPersonAppProcess(AppContext.getAccountContext().currentUser().getResume().getName());
									}else{
										assetsRevert.setPersonAppProcess(assetsRevert.getPersonAppProcess()+","+AppContext.getAccountContext().currentUser().getResume().getName());
									}
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc(AppContext.getAccountContext().currentUser().getResume().getName()+"审核");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}
						}else{
							if (wff.getPersonNum()==1) {
								if (flowVerifyDetail.getResult()==4) {
									wff.setFlowstate("2");
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(4);
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc("审核完成");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}else if(flowVerifyDetail.getResult()==1) {
									wff.setFlowstate("2");
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setShowstate("2");
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc(AppContext.getAccountContext().currentUser().getResume().getName()+"审核");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}else{
								if (flowVerifyDetail.getResult()==4) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum()-1);
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(4);
									assetsRevert.setPersonAppProcess("");
									assetsRevert.setPersonAppState(2);
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc("审核完成");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}else if(flowVerifyDetail.getResult()==1) {
									wff.setPersonNum(wff.getPersonNum()-1);
									this.getWorkFlowAndPersonService().submit(wff);
									assetsRevert.setType(2);
									assetsRevert.setShowstate("2");
									if (assetsRevert.getPersonAppProcess()==null || "".equals(assetsRevert.getPersonAppProcess().trim())) {
										assetsRevert.setPersonAppProcess(AppContext.getAccountContext().currentUser().getResume().getName());
									}else{
										assetsRevert.setPersonAppProcess(assetsRevert.getPersonAppProcess()+","+AppContext.getAccountContext().currentUser().getResume().getName());
									}
									assetsRevert.setSpr(AppContext.getAccountContext().currentUser().getResume().getName());
									assetsRevert.setSplc(AppContext.getAccountContext().currentUser().getResume().getName()+"审核");
									this.getAssetsRevertService().submit(assetsRevert);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}
						}
					}
				}
			}
		}
		return SUCCESS;
	}
	@Action("editMyAssetsRevert")
	public String editMyAssetsRevert(){
		if(assetsRevert == null){
			rec = "";
		}
		return SUCCESS;
	}
	/*******************************归还明细**************************************/
	@Action("listRevertDetail")
	public String listRevertDetail(){
		listAssetsRevert();
		return SUCCESS;
	}
	/***
	 * 根据类型进行编码的保存
	 * 
	 * @param type
	 */
	public String getCode(String type) {
	    AutoCode alist=this.getAutoCodeService().getTaskRemind(type);
	    Date dat=new Date();
	    SimpleDateFormat adf=new SimpleDateFormat("yyyyMMdd");
	    String date=adf.format(dat);
	    if(alist==null)
	    {//初始的时候调用
		    AutoCode  ac=new AutoCode();
		    ac.setCodeType(type);
		    ac.setCodeValue(type+date+"0000001");
		    ac.setAddValue("0000001");
		    this.getAutoCodeService().save(ac);	
		    return type+date+"0000001";
	    }else{
	    	String vac=alist.getAddValue();
	    	AutoCode alistA=this.getAutoCodeService().getTaskRemind(type);
	    	alistA.setCodeValue(type+date+new AutoCodeAction().addCodes(vac));
	    	alistA.setAddValue(new AutoCodeAction().addCodes(vac));
		    this.getAutoCodeService().submit(alistA);	
		    return type+date+new AutoCodeAction().addCodes(vac);
	    }
	}
	/**
	 * 顺序调整
	 * 
	 */
	public  static List<WorkFlowAndPerson>  sequens(List<WorkFlowAndPerson> ss)
	{
		List<WorkFlowAndPerson>  returnlist=new ArrayList<WorkFlowAndPerson>();
		int slength=ss.size();
		for(int i=0;i<slength;i++)
		{
			  
			for(WorkFlowAndPerson  uo:ss)
			{
				if(uo.getFlowsequen().equals(i+""))
				{
					returnlist.add(uo);
				}
			}
		}
		return returnlist;
	}
	
	@Action(value = "viewAppRevert", results = { @Result(name = "error", type = "chain", location = "listAssetsRevert") })
	public String viewAppRevert(){
		if (ids!=null) {
			this.assetsRevert=this.getAssetsRevertService().get(ids[0]);
			this.workFlowAndPersons=this.getWorkFlowAndPersonService().getWorkFlowAndPersonByAssetsRevert(assetsRevert.getWorkFlow(), assetsRevert);
			this.flowVerifyDetails=this.getFlowVerifyDetailService().getAllFlowVerifyDetails();
			return SUCCESS;
		}else{
			this.addActionError("请选择数据！");
			return ERROR;
		}
	}
}
